package com.bee.剑指offer;

import java.util.Arrays;

/**
 * @version 1.0.0
 * @Author yong.Mr
 * @data 2021-03-13
 */
public class 冒泡排序 {

    public static int[] moBaoPaiXu(int[] array) {
        int flag = 0;
        for (int i = 0; i < array.length -1; i++) {
            Boolean count = Boolean.TRUE;
            for (int j = 0; j < array.length - 1 - i; j++) {
                if(array[j] > array[j+1]){
                    flag = array[j];
                    array[j] = array[j + 1];
                    array[j + 1] = flag;
                    count = Boolean.FALSE;
                }
            }
            if (count) {
                break;
            }
        }
        return array;
    }

    public static void main(String[] args) {
        int[] array = new int[]{10,2,1,80,6,18,9,60,3};
        int[] destArray = moBaoPaiXu(array);
        System.out.println("冒泡排序之后的数据:" + Arrays.toString(destArray));
    }
}
